package com.lx.boot.log;

import com.lx.boot.OS;
import com.lx.boot.es.ElasticLowerClient;
import com.lx.boot.es.EsInfo;
import com.lx.boot.web.annotation.Auth;
import com.lx.boot.web.annotation.Auth.BoolOption;
import com.lx.boot.web.filter.SysApiEncryptFilter;
import com.lx.entity.Result;
import com.lx.util.LX;
import io.swagger.v3.oas.annotations.Hidden;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

//说明: 查询日志
/**{ ylx } 2022/4/2 13:38 */
@Slf4j
@Hidden
@RestController
@RequestMapping("/serverlog")
public class ServerLogController {

    @GetMapping("/query")
    @Auth(value = false, closeLogTrace = true,apiFilter = SysApiEncryptFilter.class, csrf = BoolOption.FALSE, firmIdRequired = BoolOption.FALSE)
    public Result<String> query(String url , String queryStr) {
        EsInfo esInfo = OS.getBeanProperty(EsInfo.class);
        if(LX.isEmpty(url) || url.contains("?") || !esInfo.effective()){
            return Result.ok();
        }
        return Result.ok(ElasticLowerClient.getInstance(esInfo).query(queryStr, url));
    }
}
